package cn.juque.singleton.lazybons;

/**
 * @author juque
 * @version 1.0.0
 * <ul>
 *     <li>懒汉模式</li>
 * </ul>
 * @date 2023-06-12 23:33:57
 **/
public class Singleton {

    private static Singleton instance = null;

    private Singleton() {
        System.out.println("我是懒汉，第一次需要我的时候才会构建哦！");
    }

    public static synchronized Singleton getInstance() {
        if(null == instance) {
            // 初始化对象
            instance = new Singleton();
        }
        return instance;
    }

    public void hello() {
        System.out.println("你好呀！我是懒汉模式！");
        System.out.println("------->>>>>>通过锁方法或锁对象实现线程安全！");
    }
}
